package main

import "fmt"

//用时11%，内存16%，6.5mb
func moveZeroes(nums []int) {
	left, right, n := 0, 0, len(nums)
	for right < n {
		if nums[right] != 0 {
			nums[left], nums[right] = nums[right], nums[left]
			left++
		}
		right++
	}
}

//用时15%，内存22%，6.5mb
func moveZeroes1(nums []int) {
	for i, n := 0, 0; n < len(nums); i++ {
		if nums[i] == 0 {
			nums = append(nums[:i], nums[i+1:]...)
			nums = append(nums, 0)
			i--
		}
		n++
	}
}

//用时94%，内存93%，6.5mb
func moveZeroes2(nums []int) {
	zero := 0
	for i := 0; i < len(nums); i++ {
		if nums[i] == 0 {
			zero++
		} else {
			nums[i], nums[i-zero] = nums[i-zero], nums[i]
		}
	}
}

func main() {
	slice := []int{1, 3, 7, 0, 7, 4, 0, 32}
	moveZeroes2(slice)
	fmt.Println(slice)
	moveZeroes1(slice)
	moveZeroes(slice)
	fmt.Println(slice[:2])

}
